package designPattern.ChainOfResponsibility;

import designPattern.ChainOfResponsibility.adapter.AnnotationMethodHandlerAdapter;
import designPattern.ChainOfResponsibility.adapter.RequestMappingHandlerAdapter;
import designPattern.ChainOfResponsibility.adapter.SimpleControllerHandlerAdapter;
import designPattern.ChainOfResponsibility.handler.RequestMappingHandler;

import java.util.ArrayList;
import java.util.List;

public class Main {

	public static void main(String[] args) {
		//前期预处理，假设链上有这三种adapter
		List<HandlerAdapter> handlerAdapterList = new ArrayList<HandlerAdapter>();
		handlerAdapterList.add(new RequestMappingHandlerAdapter());
		handlerAdapterList.add(new SimpleControllerHandlerAdapter());
		handlerAdapterList.add(new AnnotationMethodHandlerAdapter());

		//假如请求的handler为RequestMappingHandler
		RequestMappingHandler handler = new RequestMappingHandler();
		//根据职责链匹配查找，这里没有指定职责链的顺序，也是可以的
		for (HandlerAdapter ha : handlerAdapterList) {
			if (ha.supports(handler)) {
				ha.handler();
			}
		}
	}
}
